//LuoFeng Nanami ver.
#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define F(i, a, b) for(rll i = a; i <= b; i++)
#define Fdn(i, a, b) for(rll i = a; i >= b; i--)
#define int ll
#define ld long double
#define pii pair<int, int>
#define fi first
#define se second

using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f, mod = 1e9 + 7, _mod = 998244353;
const int maxn = 1e5 + 7, maxm = 1e3 + 7;

int n, m;
int _a[maxn];
int c[maxn];
pii lllg[maxn];
int a[maxn];
int x[5];
int T;
int K;
int len[maxm];
int d[maxm][maxm];
int P[62];

int num[maxn], tot;
int ans[maxn];

signed main() {
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    P[0] = 1;
    F(i, 1, 62) P[i] = P[i - 1] * 2;
    cin >> n >> m;
    F(i,1, n) cin >> _a[i];
    F(i, 1, m) { cin >> c[i]; lllg[i].fi = log2(c[i]); lllg[i].se = i; }

    sort(c + 1, c + m + 1);
    sort(lllg + 1, lllg + m + 1);
    bool flA = 1;
    F(i, 1, m) if(P[(int)log2(c[i])] != c[i]) flA = 0; 
    K = ceil(log2((ld)n));
    F(i, 1, K) {
        string str; cin >> str;
        len[i] = str.size();
        F(j, 1, len[i]) d[i][j] = str[j - 1] - '0';
    }
    cin >> T;
    F(glz, 1, T) {
        F(j, 0, 3) cin >> x[j];
        F(i, 1, n) a[i] = _a[i] ^ x[i % 4];
        if(flA) {
            int cur = 1;
            F(i, 1, n) num[i] = i; tot = P[K];
            while(lllg[cur].fi == 0) ans[lllg[cur++].se] = 1;
            F(i, 1, K) {
                for(rll j = 1; j <= min(tot, n); j += 2) {
                    int R = ((j + 1) / 2);
                    int h = (d[i][R] ? min(num[j], num[j + 1]) : max(num[j], num[j + 1])),
                        lz = (d[i][R] ? max(num[j], num[j + 1]) : min(num[j], num[j + 1]));
                    num[R] = (a[lz] >= i ? lz : h);
                    while(lllg[cur].fi == i && j == 1) ans[lllg[cur++].se] = num[R];
                }
                tot /= 2;
            }
            int answ = 1 * ans[1];
            F(i, 2, m) answ ^= (i * ans[i]);
            cout << answ << endl;
        }
    }

    return 0;
}